<%-- 
    Document   : T
    Created on : Mar 7, 2012, 7:01:29 PM
    Author     : ducquyen
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="Pojo.CauHoi"%>
<%@taglib  uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<script language="javascript">
    function timKiemCauHoi_Click(){
    
        var frm = document.getElementById("frmTimKiemCauHoi");
        var loi = "";
        
        if(frm.noiDungCauHoi.value ==""){
            
            loi+="Vui lòng nhập nội dung câu hỏi cần tìm !";
        }
        
        if(loi!=""){
            alert(loi);
        }else{
            frm.submit();
        }
            
    }
    
</script>

<div id="idcustomer">

    <div style="height: 1px"></div>
    <div id="title_thongtin"><b id="customizecauhoi">Tìm Kiếm Câu Hỏi</b></div>
    <div style="height: 20px"></div>

    <form name="frmTimKiemCauHoi" method="post" action="TimKiemCauHoicontroller?Action=TimKiem" id="frmTimKiemCauHoi">
        <div style="height: 15px"></div>
        <div id="cauhoi">
            <div style="height: 15px"></div>
            
            <div style="margin-left: 10px">

                <b style="font-weight: bold; font-size: 16px; color: blue">Nội dung câu hỏi : </b>

            </div>
            <div style="height: 15px"></div>
            <div style="margin-left : 10px;width: 500px;height: 100px">
                <textarea style="width: 640px;height: 100px" name="noiDungCauHoi" id="noiDungCauHoi" cols="85" rows="5"><% if(request.getParameter("noiDungCauHoi")!=null){out.print(request.getParameter("noiDungCauHoi"));} %></textarea>
            </div>
            <div style="height: 15px"></div>

            <div style="height: 20px"></div>
            <input style="margin-left: 500px;font-weight: bold" type="button" value="Tìm Câu Hỏi" name="btnThemCauHoi" id="btnTimCauHoi" onclick="timKiemCauHoi_Click()"/>  
    
            <div style="height: 15px"></div>
        </div>
            <div style="height: 50px"></div>
    </form>
<%
    if (session.getAttribute("timKiemCauHoi_KetQuaTimKiem") != null) {
        ArrayList<CauHoi> arrch = (ArrayList<CauHoi>) session.getAttribute("timKiemCauHoi_KetQuaTimKiem");
        if (arrch.size() > 0) {
            int soDongTrongMotTrang = 10;
            int batDau = 0;

            int trang = 1;
            if (request.getParameter("Trang") != null) {
                trang = Integer.parseInt(request.getParameter("Trang"));
                batDau = (trang - 1) * soDongTrongMotTrang;
            }

            int ketThuc = batDau + soDongTrongMotTrang;
            if (ketThuc > arrch.size()) {
                ketThuc = arrch.size();
            }

%>
<div style="height: 20px"></div>
<div id="title_thongtin"><b id="customizecauhoi">Kết Quả Tìm Kiếm Câu Hỏi</b></div>
<div style="height: 20px"></div>
<div id="cauhoi">

    <table>
        <tr>
            <td style="width: 20px">Mã Câu Hỏi</td>
            <td  style="width: 400px">Nội Dung</td>
            <td style="width: 80px">Cập Nhật</td>
        </tr>

        <%
            for (int i = batDau; i < ketThuc; i++) {
                CauHoi ch = arrch.get(i);
        %>
        <tr>
            <td ><input style="width: 80px" type="text" value="<%= ch.getMaCauHoi()%>"/></td>
            <td  style="width: 500px">
                <textarea style="width: 496px;height: 50px" name="noiDungCauHoi" id="noiDungCauHoi" cols="85" rows="5"><%=ch.getNoiDungCauHoi()%></textarea>
            </td>
            <td style="width: 120px"><a href="CapNhatCauHoicontroller?Action=View&MaCauHoi=<%=ch.getMaCauHoi()%>" >Cập Nhật</a> </td>
        </tr>
        <%            }

        %>
    </table>
</div>
<%


%>



<div style="height: 20px"></div>


<div style="margin-left: 10px;margin-right: 10px ; text-align: center">Trang : 

    <%
        if (request.getParameter("Trang") != null) {
            int soLuongTrang = arrch.size() / soDongTrongMotTrang ;
            String noiDungTimKiem = request.getParameter("noiDungCauHoi");
            if (trang > 1) {%>
    <a href="TimKiemCauHoicontroller?Action=TimKiem&Trang=<%=1%>&noiDungCauHoi=<%=noiDungTimKiem%>">[Đầu]</a>
    <a href="TimKiemCauHoicontroller?Action=TimKiem&Trang=<%=trang - 1%>&noiDungCauHoi=<%=noiDungTimKiem%>">[Trước]</a>
    <%  }

        for (int i = 1; i <= soLuongTrang; i++) {
    %>
    <a href="TimKiemCauHoicontroller?Action=TimKiem&Trang=<%=i%>&noiDungCauHoi=<%=noiDungTimKiem%>" style="<%if (trang == i) {
            out.print("font-size: large ;font-weight: bold");
        }%>" > <%=i%> </a>

    <%  }

        if (trang < soLuongTrang) {

    %>
    <a href="TimKiemCauHoicontroller?Action=TimKiem&Trang=<%=trang + 1%>&noiDungCauHoi=<%=noiDungTimKiem%>">[Sau]</a>
    <a href="TimKiemCauHoicontroller?Action=TimKiem&Trang=<%=soLuongTrang%>&noiDungCauHoi=<%=noiDungTimKiem%>">[Cuối]</a>
    <%  }
                }
            }
               }
    %>
    <div style="height: 50px"></div>
</div>
</div>